import {handleActions} from 'redux-actions';

import { USER_LOGIN, USER_MENU, USER_LOGOUT } from '../actions/ActionTypes.js'

const login = handleActions({
  [USER_LOGIN.REQUEST](state) {
    return {...state, loading: true,};
  },
  [USER_LOGIN.SUCCESS](state, action) {
    return {...state, ...action.payload, loading: false,};
  },
  [USER_LOGIN.FAILURE](state, action) {
    return {...state, err: action.err, loading: false,};
  },
  [USER_MENU.REQUEST](state) {
    return {...state, loading: true,};
  },
  [USER_MENU.SUCCESS](state, action) {
    return {...state, menu: action.payload, loading: false,};
  },
  [USER_MENU.FAILURE](state, action) {
    return {...state, err: action.err, loading: false,};
  },
  [USER_LOGOUT.REQUEST](state) {
    return {...state };
  },
  [USER_LOGOUT.SUCCESS](state, action) {
    return {...state };
  },
  [USER_LOGOUT.FAILURE](state, action) {
    return {...state, err: action.err};
  },
}, {
  loading:false,
  menu:[],
  err:{}
});

export default login;
